﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TFXK.BLL;
using log4net;
using System.Collections.Generic;
using TFXK.Model;


using System.IO;
using System.Net;
using System.Web.Caching;
public partial class Default : System.Web.UI.Page
{

    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private static readonly CategoryBLL bllCategory = new CategoryBLL();
    private static readonly NewsBLL bllNews = new NewsBLL();
    private static readonly MessageBLL bllMessage = new MessageBLL();
    private static readonly TravelLinesBLL bllTravelLines = new TravelLinesBLL();
    private static readonly PicturesBLL bllPictures = new PicturesBLL();
    private static readonly HotelBLL bllHotel = new HotelBLL();
    private static readonly AdsBLL bllAds = new AdsBLL();
    int rowCount = 0;
    public int k = 1;
    public int j = 1;
    public int l = 1;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                BindLeftNews();
                BindTravelLine();
                BindHotel();
                BindAds();
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
        }
    }
    //绑定文章
    public void BindLeftNews()
    {
        rptTravelNews.DataSource = bllNews.GetList(10, 1, "lyxx", out rowCount);
        rptTravelNews.DataBind();

        rptNewLYSX.DataSource = bllNews.GetList(10, 1, "lysx", out rowCount);
        rptNewLYSX.DataBind();

        rptNewLYGL.DataSource = bllNews.GetList(9, 1, "lygl", out rowCount);
        rptNewLYGL.DataBind();

        rptMsg.DataSource = bllMessage.GetWebList(7, 1, out rowCount);
        rptMsg.DataBind();

        DataSet ds = bllNews.GetList(8, 1, "xxss", out rowCount);
        rptXXSSWZ.DataSource = ds;
        rptXXSSWZ.DataBind();
        if (ds != null)
        {
            while (ds.Tables[0].Rows.Count > 5)
            {
                ds.Tables[0].Rows.RemoveAt(5);
            }
            try
            {
                imgBigXXSS.Visible = true;
                int id = int.Parse("" + ds.Tables[0].Rows[0]["id"]);
                int tid = int.Parse("" + ds.Tables[0].Rows[0]["parentId"]);
                string picpath = bllPictures.GetModel(id, tid).imgPath;
                if (!string.IsNullOrEmpty(picpath))
                {
                    imgBigXXSS.ImageUrl = "uploads/" + picpath;
                    imgBigXXSS.ToolTip = ds.Tables[0].Rows[0]["title"] + "";
                    imgBigLink.NavigateUrl = "TravelDocInfo.aspx?Key=" + id;
                }
                else
                {
                    imgBigXXSS.ImageUrl = "images/nopic.jpg";
                    imgBigXXSS.ToolTip = ds.Tables[0].Rows[0]["title"] + "";
                }
                ds.Tables[0].Rows.RemoveAt(0);
            }
            catch
            {
                imgBigXXSS.Visible = false;
            }

            RptImages.DataSource = ds;
            RptImages.DataBind();
        }


    }
    public string GetPics(object ids, object pids)
    {
        try
        {
            int pid = int.Parse(pids + "");
            int id = int.Parse(ids + "");
            return "uploads/" + bllPictures.GetModel(id, pid).imgPath;
        }
        catch
        {
            return "images/nopic.jpg";
        }

    }

    public void BindTravelLine()
    {
        rptSNTravels.DataSource = bllTravelLines.GetList(6, "isSNHot=1 and theState=1", "orderid desc,id desc");
        rptSNTravels.DataBind();

        rptGNTravels.DataSource = bllTravelLines.GetList(6, "isGNHot=1 and theState=1", "orderid desc,id desc");
        rptGNTravels.DataBind();

        rptCJTravels.DataSource = bllTravelLines.GetList(6, "isCJTTuiJian=1 and theState=1", "orderid desc,id desc");
        rptCJTravels.DataBind();

        rptZBOneDay.DataSource = bllTravelLines.GetList(3, "isZBTravel=1 and cycleDays<3 and theState=1", "orderid desc,id desc");
        rptZBOneDay.DataBind();

        rptZBThreeDay.DataSource = bllTravelLines.GetList(3, "isZBTravel=1 and cycleDays>=3 and cycleDays<=4 and theState=1", "orderid desc,id desc");
        rptZBThreeDay.DataBind();

        rptZBFiveDay.DataSource = bllTravelLines.GetList(3, "isZBTravel=1 and cycleDays>=5 and theState=1", "orderid desc,id desc");
        rptZBFiveDay.DataBind();

        //古镇旅游
        rptGuZhen.DataSource = bllTravelLines.GetWebList(5, 1, "theState=1 and travelShowType=" + bllCategory.GetIdByCodeNo("gzly"), out rowCount);
        rptGuZhen.DataBind();

        rptGZTJTour.DataSource = bllTravelLines.GetWebList(5, 1, "theState=1 and isShowJD=1 and travelShowType=" + bllCategory.GetIdByCodeNo("gzly"), out rowCount);
        rptGZTJTour.DataBind();


        //城市旅游
        rptCityTravel.DataSource = bllTravelLines.GetWebList(5, 1, "theState=1 and travelShowType=" + bllCategory.GetIdByCodeNo("csgg"), out rowCount);
        rptCityTravel.DataBind();

        rptCityTour.DataSource = bllTravelLines.GetWebList(5, 1, "theState=1 and isShowJD=1 and travelShowType=" + bllCategory.GetIdByCodeNo("csgg"), out rowCount);
        rptCityTour.DataBind();


        rptSMTXTravel.DataSource = bllTravelLines.GetWebList(5, 1, "theState=1 and travelShowType=" + bllCategory.GetIdByCodeNo("smtx"), out rowCount);
        rptSMTXTravel.DataBind();

        rptZTTitle.DataSource = bllCategory.GetNextNodeByCode("ztly");
        rptZTTitle.DataBind();

        DataSet ds = bllAds.GetList(3, 1, out rowCount);

        rptBigImg.DataSource = ds;
        rptBigImg.DataBind();

        rptSmallImg.DataSource = ds;
        rptSmallImg.DataBind();
        //主题旅游 
        // string subids = bllCategory.GetAllChildIDByCode("ztly");
        rptZTSHowImg.DataSource = bllAds.GetList(6, 2, out rowCount);
        rptZTSHowImg.DataBind();


    }

    //绑定酒店

    public void BindHotel()
    {
        //成都 57
        //峨眉山 107
        //九寨沟 108
        //乐山    109
        //海螺沟 110
        this.rptHotelCD.DataSource = bllHotel.GetList(12, 1, "", 0, 57, out rowCount);
        rptHotelCD.DataBind();

        this.rptHotelEMS.DataSource = bllHotel.GetList(12, 1, "", 0, 107, out rowCount);
        rptHotelEMS.DataBind();

        this.rptHotelJZG.DataSource = bllHotel.GetList(12, 1, "", 0, 108, out rowCount);
        rptHotelJZG.DataBind();

        this.rptHotelLS.DataSource = bllHotel.GetList(12, 1, "", 0, 109, out rowCount);
        rptHotelLS.DataBind();

        this.rptHotelHLG.DataSource = bllHotel.GetList(12, 1, "", 0, 110, out rowCount);
        rptHotelHLG.DataBind();

    }

    //设置星级
    public string SetStarWidth(object obj)
    {
        try
        {
            int num = int.Parse(obj + "");
            return num * 12 + "";
        }
        catch
        {
            return "0";
        }
    }


    public string GetLineLink(object tids, object id)
    {
        int tid = int.Parse(tids + "");
        if (tid == 41)
        {
            return "GN_TravelInfo.aspx?Key=" + id;
        }
        else if (tid == 42)
        {
            return "CJ_TravelInfo.aspx?Key=" + id;
        }
        else if (tid == 43)
        {
            return "ZY_TravelInfo.aspx?Key=" + id;
        }
        else if (tid == 44)
        {
            return "YL_TravelInfo.aspx?Key=" + id;
        }
        else
        {
            return "GN_TravelInfo.aspx?Key=" + id;
        }
    }




    #region 设置广告
    public void BindAds()
    {
        List<Ads> ads = bllAds.GetADSModelList();
        if (ads == null)
        {
        }
        else
        {
            try
            {
                imgAds1.ImageUrl = "uploads/" + ads[3].linkImage;
                hlkAds.NavigateUrl = ads[3].linkUrl;
            }
            catch
            {
                hlkAds.Visible = false;
                imgAds1.Visible = false;
            }
            try
            {
                imgAds2.ImageUrl = "uploads/" + ads[4].linkImage;
                hlkAds2.NavigateUrl = ads[4].linkUrl;
            }
            catch
            {
                hlkAds2.Visible = false;
                imgAds2.Visible = false;
            }
            try
            {
                imgAds3.ImageUrl = "uploads/" + ads[5].linkImage;
                hlkAds3.NavigateUrl = ads[5].linkUrl;
            }
            catch
            {
                hlkAds3.Visible = false;
                imgAds3.Visible = false;
            }
        }
    }

    #endregion



}
